<? 
include("../connect.php");
$nama=$_POST["nama"];
$jenis=$_POST["jenis"];
$tgl=$_POST["tgl"];
$bln=$_POST["bln"];
$thn=$_POST["thn"];
$tanggal=$thn.'-'.$bln.'-'.$tgl;
if (empty($nama)) {
	echo " <SCRIPT> alert(\"ERROR ! Anda belum memasukkan nama kegiatan.\") </SCRIPT> ";
	mysql_close($conn);
	echo "<script type=\"text/javascript\">";
	echo "history.go(-1)";
	echo "</script>";
	exit;
}
$pilih=mysql_select_db("uwika_skk",$conn);
$sqlstr="SELECT nama from kegiatan where nama = '$nama' and tanggal = '$tanggal'";
$hasil=mysql_query($sqlstr);
list($dobel) = mysql_fetch_row($hasil);
if (!empty($dobel)) {
	echo " <SCRIPT> alert(\"ERROR ! Nama kegiatan yang anda masukkan sudah ada.\") </SCRIPT> ";
	mysql_close($conn);
	echo "<script type=\"text/javascript\">";
	echo "history.go(-1)";
	echo "</script>";
	exit;
}
$sqlstr="SELECT max(kode) as kode from kegiatan";
$hasil=mysql_query($sqlstr);
list($kode) = mysql_fetch_row($hasil);
$kode=$kode+1;
$sqlstr="insert into kegiatan (kode,nama,jenis,tanggal) values ('$kode','$nama','$jenis','$tanggal')";
$hasil=mysql_query($sqlstr);
mysql_close($conn);
echo " <SCRIPT> alert(\"Data anda telah disimpan.\") </SCRIPT> ";
echo "<meta http-equiv=\"refresh\" content=\"0; url=set_kegiatan.php\">";
echo "Klik <a href=\"set_kegiatan.php\">disini</a> apabila browser anda berhenti berjalan ...";
?>
